import Vue from 'vue'
import Element from 'element-ui'
import App from '@/App'
import i18n from '@/i18n'
import router from '@/router'
import store from '@/store'
import '@/icons'
import '@/element-ui/theme/index.css'
import '@/assets/scss/aui.scss'
// 挂载全局http请求全局方法
import http from '@/utils/request'
Vue.prototype.$http = http

// 引用vue-lottie动画
import lottie from 'vue-lottie'
Vue.component('lottie', lottie)


//websocket全局方法
import socketPublic from '@/utils/websocket/index.js'
Vue.prototype.$socketPublic = socketPublic

// 将自动注册所有组件为全局组件--大屏显示
import dataV from '@jiaminghi/data-view'
Vue.use(dataV)

//获取字典的全局方法
import { getDict, getDictList } from '@/utils/dict'
Vue.prototype.$getDict = getDict
Vue.prototype.$getDictList = getDictList

//swiper轮播组件
import "swiper/css/swiper.min.css" //cnpm i swiper@5 vue-awesome-swiper@4

//moment时间
import moment from "moment";
Vue.prototype.$moment = moment;

Vue.config.productionTip = false
Vue.use(Element, {
    size: 'default',
    i18n: (key, value) => i18n.t(key, value)
})

//滚动到底部加载更多
Vue.directive('loadmore', {
    bind(el, binding) {
        const selectWrap = el.querySelector('.el-table__body-wrapper');
        let oldScrollTop = 0;
        let isToTop = false;
        selectWrap.addEventListener('scroll', function() {
            // console.log("scrollHeight", this.scrollHeight)
            // console.log("scrollTop", this.scrollTop)
            // console.log("clientHeight", this.clientHeight)
            let sign = 2
            if (oldScrollTop < this.scrollTop) isToTop = false;
            else isToTop = true;
            oldScrollTop = this.scrollTop
                // if ((this.scrollHeight - this.clientHeight) == this.scrollTop) return
            const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight;
            if (Math.ceil(scrollDistance) <= sign && !isToTop) {
                binding.value()
            }
        })
    },
})

new Vue({
    i18n,
    router,
    store,
    render: h => h(App)
}).$mount('#app')